package org.rsbot.script.internal.wrappers;

import org.rsbot.client.Node;
import org.rsbot.client.NodeDeque;

public class Deque<N>
{
  private final NodeDeque nl;
  private Node current;

  public Deque(NodeDeque paramNodeDeque)
  {
    this.nl = paramNodeDeque;
  }

  public int size() {
    int i = 0;
    Node localNode = this.nl.getTail().getPrevious();

    while (localNode != this.nl.getTail()) {
      localNode = localNode.getPrevious();
      i++;
    }

    return i;
  }

  public N getHead() {
    Node localNode = this.nl.getTail().getNext();

    if (localNode == this.nl.getTail()) {
      this.current = null;
      return null;
    }
    this.current = localNode.getNext();

    return localNode;
  }

  public N getTail() {
    Node localNode = this.nl.getTail().getPrevious();

    if (localNode == this.nl.getTail()) {
      this.current = null;
      return null;
    }
    this.current = localNode.getPrevious();

    return localNode;
  }

  public N getNext() {
    Node localNode = this.current;

    if (localNode == this.nl.getTail()) {
      this.current = null;
      return null;
    }
    this.current = localNode.getNext();

    return localNode;
  }
}